﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SchoolManagerMVC.BusinessAbstract.Interfaces;
using SchoolManagerMVC.Repository.EntityFramework;
using SchoolManagerMVC.Web.Areas.Courses.ViewModels;

namespace SchoolManagerMVC.Web.Areas.Students.Controllers
{
    public class EnrollmentController : Controller
    {
        /// <summary>
        /// Student Area
        /// </summary>
        private IRepository _repo;
        public EnrollmentController(IRepository repo)
        {
            _repo = repo;
            if (_repo == null)
                throw new NullReferenceException();
        }

        /*
        public ActionResult Index(Guid ?id)
        {
            if (id == null)
                return RedirectToAction("Index", "Home", null);

            ViewBag.CourseList = _repo.GetAll<Course>();
            var student = _repo.GetSingle<Student>(e => e.UniqueID == (Guid)id) as Student;

            ViewBag.UniqueID = student.UniqueID;
            return View(new StudentInCourse()
            {
                StudentID = student.StudentID                
            });
        }

        public ActionResult StudentsCourses(Guid id)
        {
            var StudentID = _repo.GetWhere<Student>(e => e.UniqueID == id).FirstOrDefault().StudentID;
            List<CourseViewModel> StudentsCourses = (List<CourseViewModel>)_repo.GetAll<StudentInCourse>().Where(e => e.StudentID == StudentID).Select(f => new CourseViewModel()
            {
                course = (Course)_repo.GetWhere<Course>(e=>e.CourseID == f.CourseID).FirstOrDefault(),
                TeacherName = _repo.GetWhere<FacultyMember>(e => e.FacultyID == f.Course.Teacher).FirstOrDefault().FirstLast,
                DepartmentName = _repo.GetWhere<Department>(e=>e.DepartmentID == f.Course.Department).FirstOrDefault().Name
            }).ToList();


            ViewBag.StudentID = id;
            return View(StudentsCourses);
        }
         * */
    }
}
